﻿namespace ExamV5.WAPPage
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmShowUserExam : Page
    {
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected ImageButton ImgButExit;
        protected ImageButton ImgLook;
        private int int_0 = 0;
        protected Label labDiff;
        protected Label labExamName;
        protected Label labFen;
        protected Label labGetFen;
        protected Label labRubricDist;
        protected Label labSETime;
        protected Label labSubjectName;
        private PublicFun publicFun_0 = new PublicFun();
        private string string_0 = "";
        private string string_1 = "";

        protected void ImgButExit_Click(object sender, ImageClickEventArgs e)
        {
            base.Response.Cookies["ExamUserCode"].Value = "";
            base.Response.Cookies["ExamUserName"].Value = "";
            base.Response.Cookies["ExamDeptName"].Value = "";
            base.Response.Cookies["ExamDeptID"].Value = "";
            base.Response.Cookies["ExamWorker"].Value = "";
            base.Response.Cookies["ExamUserSex"].Value = "";
            base.Response.Cookies["ExamUserLevel"].Value = "";
            base.Response.Cookies["ExamUserGWName"].Value = "";
            base.Response.Cookies["ExamUserGWLevel"].Value = "";
            base.Response.Redirect("FrmLogin.aspx");
        }

        protected void ImgLook_Click(object sender, ImageClickEventArgs e)
        {
            string str;
            if (!(this.httpCookie_2.Value == "A"))
            {
                this.string_1 = base.Server.UrlDecode(base.Request["UserCode"].ToString());
            }
            else
            {
                this.string_1 = this.httpCookie_0.Value;
            }
            if (this.httpCookie_2.Value == "A")
            {
                if (!(this.ViewState["UserPower"].ToString() == "Y"))
                {
                    base.Response.Write("<script>alert('查看考卷权限暂未开放');</script>");
                }
                else
                {
                    string values = this.publicFun_0.GetValues("select LookPaperID from UserPower where UserCode='" + this.httpCookie_0.Value + "'", "LookPaperID");
                    if (!(values.Trim() != ""))
                    {
                        str = base.Request.Url.ToString();
                        str = str.Substring(0, str.LastIndexOf('/') + 1);
                        base.Response.Redirect(string.Concat(new object[] { str, "FrmLookStudy.aspx?UserCode=", base.Server.UrlEncode(this.string_1), "&ID=", this.int_0 }));
                    }
                    else if (values.Trim().IndexOf("," + this.int_0.ToString() + ",") < 0)
                    {
                        base.Response.Write("<script>alert('查看考卷权限暂未开放');</script>");
                    }
                    else
                    {
                        str = base.Request.Url.ToString();
                        str = str.Substring(0, str.LastIndexOf('/') + 1);
                        base.Response.Redirect(string.Concat(new object[] { str, "FrmLookStudy.aspx?UserCode=", base.Server.UrlEncode(this.string_1), "&ID=", this.int_0 }));
                    }
                }
            }
            else
            {
                str = base.Request.Url.ToString();
                str = str.Substring(0, str.LastIndexOf('/') + 1);
                base.Response.Redirect(string.Concat(new object[] { str, "FrmLookStudy.aspx?UserCode=", base.Server.UrlEncode(this.string_1), "&ID=", this.int_0 }));
            }
        }

        private void method_0()
        {
            string cmdText = string.Concat(new object[] { "select b.StudyPlanID,b.JoinExamNum,a.JoinExamNum as ExamNum,b.RubricTypeName,b.NoWriteFen,b.ErrorFen,b.RubricDist,b.FenDist,b.PaperDiff,a.GetCountFen,a.Flag,b.ID,b.ExamName,b.SubjectName,b.PaperFen,b.ExamTime,b.PaperStartTime,b.PaperEndTime from ExamUser a ,PaperInfo b  where  b.PaperStatus='A' and  a.UserCode='", this.string_1, "'  and a.PaperID=b.ID and b.ISCheck='N' and b.ID=", this.int_0 });
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = new SqlCommand(cmdText, connection);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            if (!reader.Read())
            {
                goto Label_09EA;
            }
            this.labExamName.Text = reader["ExamName"].ToString();
            this.labSubjectName.Text = reader["SubjectName"].ToString();
            this.labFen.Text = reader["PaperFen"].ToString();
            this.labSETime.Text = reader["PaperStartTime"].ToString().Substring(0, reader["PaperStartTime"].ToString().Length - 3) + "—" + reader["PaperEndTime"].ToString().Substring(0, reader["PaperEndTime"].ToString().Length - 3);
            string str5 = reader["PaperDiff"].ToString();
            switch (str5)
            {
                case null:
                    goto Label_01FC;

                case "A":
                    this.labDiff.Text = "难";
                    goto Label_01FC;

                case "B":
                    this.labDiff.Text = "较难";
                    goto Label_01FC;

                case "C":
                    this.labDiff.Text = "中等";
                    break;
            }
            if (str5 == "C")
            {
                this.labDiff.Text = "中等";
            }
            else if (!(str5 == "D"))
            {
                if (str5 == "E")
                {
                    this.labDiff.Text = "容易";
                }
            }
            else
            {
                this.labDiff.Text = "较易";
            }
        Label_01FC:;
            string[] strArray = reader["RubricDist"].ToString().Split(new char[] { '#' });
            string[] strArray4 = reader["FenDist"].ToString().Split(new char[] { '#' });
            string[] strArray5 = reader["NoWriteFen"].ToString().Split(new char[] { '#' });
            string[] strArray6 = reader["ErrorFen"].ToString().Split(new char[] { '#' });
            string[] strArray3 = reader["RubricTypeName"].ToString().Split(new char[] { '#' });
            for (int i = 0; i < strArray.Length; i++)
            {
                if (strArray[i].ToString() != "0")
                {
                    this.labRubricDist.Text = this.labRubricDist.Text + "<br>" + strArray3[i] + ":<font color='red'>" + strArray[i] + "</font>道，每道<font color='red'>" + strArray4[i] + "</font>分";
                }
                if (i < 3)
                {
                    if (strArray5[i].ToString() != "0")
                    {
                        this.labRubricDist.Text = this.labRubricDist.Text + "，未答倒扣<font color='red'>" + strArray5[i] + "</font>分/道";
                    }
                    if (strArray6[i].ToString() != "0")
                    {
                        this.labRubricDist.Text = this.labRubricDist.Text + "，答错倒扣<font color='red'>" + strArray6[i] + "</font>分/道";
                    }
                }
                if ((i == 9) && (strArray[9].ToString().Length > 1))
                {
                    this.labRubricDist.Text = this.labRubricDist.Text + "<br>" + strArray3[i] + ":<font color='red'>" + Convert.ToString(strArray[9].ToString().Split(new char[] { '_' }).Length) + "</font>道，每道<font color='red'>" + strArray4[9].ToString().Replace("_", " /") + "</font>分/空";
                }
            }
            if (this.labRubricDist.Text.Length > 4)
            {
                this.labRubricDist.Text = this.labRubricDist.Text.Substring(4);
            }
            str5 = reader["Flag"].ToString();
            if (str5 == null)
            {
                goto Label_0653;
            }
            if (str5 == "A")
            {
                this.labGetFen.Text = "暂未作答";
                this.ImgLook.ImageUrl = "image/butLookMXDis.jpg";
                this.ImgLook.Enabled = false;
            }
            else if (str5 == "B")
            {
                this.labGetFen.Text = reader["GetCountFen"].ToString();
                this.ImgLook.ImageUrl = "image/butLookMXDis.jpg";
                this.ImgLook.Enabled = false;
            }
            else if (str5 == "C")
            {
                this.labGetFen.Text = reader["GetCountFen"].ToString();
                this.ImgLook.ImageUrl = "image/butLookMX.jpg";
            }
            else if (str5 == "D")
            {
                this.labGetFen.Text = reader["GetCountFen"].ToString();
                this.ImgLook.ImageUrl = "image/butLookMX.jpg";
            }
            else
            {
                if (!(str5 == "E"))
                {
                    goto Label_0653;
                }
                this.labGetFen.Text = reader["GetCountFen"].ToString();
                this.ImgLook.ImageUrl = "image/butLookMX.jpg";
            }
            goto Label_067F;
        Label_0653:
            this.labGetFen.Text = reader["GetCountFen"].ToString();
            this.ImgLook.ImageUrl = "image/butLookMXDis.jpg";
        Label_067F:
            if (reader["Flag"].ToString() != "A")
            {
                double num = Convert.ToDouble(reader["GetCountFen"].ToString());
                if ((this.httpCookie_2.Value == "A") && (this.ViewState["IsGradeLook"].ToString() == "N"))
                {
                    this.ImgLook.Enabled = false;
                    this.ImgLook.ImageUrl = "image/butLookMXDis.jpg";
                    this.labGetFen.Text = "";
                }
                if ((this.string_0 == "") || (this.string_0 == "Y"))
                {
                    string values = this.publicFun_0.GetValues(string.Concat(new object[] { "select ReuleName from GradeReule where PaperID=", this.int_0, " and MinValue<=", num, " and ", num, "<=MaxValue" }), "ReuleName");
                    if (values.Trim() == "")
                    {
                        values = this.publicFun_0.GetValues(string.Concat(new object[] { "select ReuleName from GradeReule where PaperID=0 and MinValue<=", num, " and ", num, "<=MaxValue" }), "ReuleName");
                        if (values.Trim() == "")
                        {
                            values = "未定义";
                        }
                    }
                    this.labGetFen.Text = this.labGetFen.Text + "<font color=red>(" + values + ")</font>";
                }
                if (this.ViewState["IsGradeSort"].ToString() != "N")
                {
                    this.labGetFen.Text = this.labGetFen.Text + "&nbsp;&nbsp;&nbsp;&nbsp;排名：" + this.method_1(this.int_0.ToString());
                }
            }
            if (this.httpCookie_2.Value == "A")
            {
                if (this.ViewState["UserPower"].ToString() != "Y")
                {
                    this.ImgLook.Enabled = false;
                    this.ImgLook.ImageUrl = "image/butLookMXDis.jpg";
                }
                else
                {
                    string str3 = this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='LookPaperFlag'", "ParmValue").Trim();
                    if ((str3.Trim() != "Y") && !(str3.Trim() == ""))
                    {
                        if (!(str3.Trim() == "N") || !(reader["Flag"].ToString() == "E"))
                        {
                            this.ImgLook.Enabled = false;
                            this.ImgLook.ImageUrl = "image/butLookMXDis.jpg";
                        }
                        else
                        {
                            this.ImgLook.ImageUrl = "image/butLookMX.jpg";
                        }
                    }
                    else
                    {
                        this.ImgLook.ImageUrl = "image/butLookMX.jpg";
                    }
                }
            }
            else
            {
                this.ImgLook.Enabled = true;
                this.ImgLook.ImageUrl = "image/butLookMX.jpg";
            }
        Label_09EA:
            reader.Close();
            command.Dispose();
            connection.Close();
            connection.Dispose();
        }

        private string method_1(string string_2)
        {
            string str = "0";
            int num = 0;
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = new SqlCommand("select * from ExamUser where PaperID=" + string_2 + " and  (Flag<>'A' and Flag<>'B') order by GetCountFen desc", connection);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            while (reader.Read())
            {
                num++;
                if (reader["UserCode"].ToString().Trim() == this.httpCookie_0.Value)
                {
                    str = num.ToString();
                }
            }
            reader.Close();
            command.Dispose();
            connection.Close();
            connection.Dispose();
            return str;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if (!((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false))
            {
                base.Response.Write("<script language=javascript>window.location.href='FrmLogin.aspx';</script>");
            }
            else
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.int_0 = Convert.ToInt32(base.Request["ID"]);
                if (!base.IsPostBack)
                {
                    this.string_0 = this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='IsGradeStand'", "ParmValue").Trim();
                    this.ViewState["UserPower"] = this.publicFun_0.GetValues("select LookPaper from UserPower where UserCode='" + this.httpCookie_0.Value + "'", "LookPaper");
                    this.ViewState["IsGradeSort"] = this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='IsGradeSort'", "ParmValue").Trim();
                    this.ViewState["IsGradeLook"] = this.publicFun_0.GetValues("select ParmValue from SysParmInfo where ParmMemo='IsGradeLook'", "ParmValue").Trim();
                    if (!(this.httpCookie_2.Value == "A"))
                    {
                        this.string_1 = base.Server.UrlDecode(base.Request["UserCode"].ToString());
                        this.string_0 = "Y";
                        this.ViewState["UserPower"] = "Y";
                        this.ViewState["IsGradeSort"] = "Y";
                        this.ViewState["IsGradeLook"] = "Y";
                    }
                    else
                    {
                        this.string_1 = this.httpCookie_0.Value;
                    }
                    this.Page.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString;
                    this.method_0();
                    if (this.labExamName.Text.Trim() == "")
                    {
                        this.ImgLook.Enabled = false;
                        this.ImgLook.ImageUrl = "image/butLookMXDis.jpg";
                    }
                    if (this.ImgLook.ImageUrl == "image/butLookMXDis.jpg")
                    {
                        this.ImgLook.Enabled = false;
                    }
                    else
                    {
                        this.ImgLook.Enabled = true;
                    }
                }
            }
        }
    }
}

